using AndroidCaller;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

public class GameUI : MonoBehaviour
{
	public static GameUI instance;

	public CoinsController CoinsController;

	public Text coins_value;

	public Text bonus_points_text;

	private Animation bonus_animation;

	public GameObject dialogs_gui;

	public GameObject pause_dialog;

	public GameObject crash_dialog;

	public GameObject finish_dialog;

	public Text finish_level_bonus;

	public GameObject finish_game_dialog;

	public Text finish_game_level_bonus;

	public bool dialog_showing;

	private MyAdManager adManage;

	private void Start()
	{
		instance = this;
		if (coins_value != null)
		{
			coins_value.text = string.Empty + CoinsController.GetCurrentCoins();
		}
		if (bonus_points_text != null)
		{
			bonus_animation = bonus_points_text.GetComponent<Animation>();
		}
		HideAllDialogs();
		Time.timeScale = 1f;
		AudioListener.pause = false;
		adManage = new MyAdManager();

	}

	private void Update()
	{
		if (UnityEngine.Input.GetKeyDown(KeyCode.Escape))
		{
			PauseClick();
		}
	}

	public static GameUI GetInstance()
	{
		return instance;
	}

	public void UpdateCoinsDisplay()
	{
		if (coins_value != null)
		{
			coins_value.text = string.Empty + CoinsController.GetCurrentCoins();
		}
	}

	public void UpdateCoinsDisplay(int type, string text)
	{
		if (coins_value != null)
		{
			coins_value.text = string.Empty + CoinsController.GetCurrentCoins();
		}
		if (bonus_animation != null)
		{
			bonus_points_text.text = text;
			bonus_animation.Play();
		}
	}

	public void HideAllDialogs()
	{
		pause_dialog.SetActive(value: false);
		crash_dialog.SetActive(value: false);
		finish_dialog.SetActive(value: false);
		finish_game_dialog.SetActive(value: false);
		dialogs_gui.SetActive(value: false);
		dialog_showing = false;
	}

	public void PauseDialogShow()
	{
		MyAdManager.Instance.MyShowNative(0f);
		dialog_showing = true;
		Time.timeScale = 0.01f;
		AudioListener.pause = true;
		dialogs_gui.SetActive(value: true);
		pause_dialog.SetActive(value: true);
	}
	private bool isDead = false;
	public void CrashDialogShow()
	{
		if (isDead == false)
		{
			AdManager.Instance.ShowNative(0f);
			dialog_showing = true;
			dialogs_gui.SetActive(value: true);
			crash_dialog.SetActive(value: true);
			Time.timeScale = 0.1f;
			isDead = true;
		}
	}

	public void FinishDialogShow(string text)
	{
		AdManager.Instance.ShowNative(0f);
		dialog_showing = true;
		dialogs_gui.SetActive(value: true);
		finish_dialog.SetActive(value: true);
		finish_level_bonus.text = text;
		PlayerPrefs.SetInt("level_current_reach", PlayerPrefs.GetInt("level_current_reach", 0) + 1);
		Time.timeScale = 0.05f;
	}

	public void FinishGameDialogShow(string text)
	{
		AdManager.Instance.ShowNative(0f);
		dialog_showing = true;
		dialogs_gui.SetActive(value: true);
		finish_game_dialog.SetActive(value: true);
		finish_game_level_bonus.text = text;
		Time.timeScale = 0.05f;
	}

	public void LightsClick()
	{
		PoliceLights.GetInstance().SwitchLightState();
	}

	public void PauseClick()
	{
		if (!dialog_showing)
		{
			PauseDialogShow();
		}
	}

	public void MainMenuClick()
	{
		Time.timeScale = 1f;
		//NativeCall.Call("gamebreak");
		SceneManager.LoadScene("Menu");
		// adManage.MyShowNative();
	}

	public void RestartClick()
	{
		isDead = false;
		Time.timeScale = 1f;
		//NativeCall.Call("gamebreak");
		SceneManager.LoadScene("Scene");
		// adManage.MyShowNative();
	}

	public void ResumeClick()
	{
		HideAllDialogs();
		Time.timeScale = 1f;
		AudioListener.pause = false;
	}

	public void NextLevelClick()
	{
		Time.timeScale = 1f;
		PlayerPrefs.SetInt("selected_level", PlayerPrefs.GetInt("selected_level", 0) + 1);
		SceneManager.LoadScene("Scene");
	}

	public void AfterAdHandle()
	{
	}
}
